package router;

import java.net.InetAddress;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import server.UDPServer;

import client.UDPClient;


public class Router {
	
	private String id;
	private InetAddress ipAddress;
	private int port;
	private RouteTable routeTable;
	//<Id, custo>
	private HashMap<String, Integer> neighbors = new HashMap<String, Integer>();
	private UDPClient client;
	private UDPServer server;
	private boolean isOn;
	
	public Router(String id, InetAddress ipAddress, int port) {
		this.id = id;
		this.ipAddress = ipAddress;
		this.port = port;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public InetAddress getIpAddress() {
		return ipAddress;
	}

	public void setIpAddress(InetAddress ipAddress) {
		this.ipAddress = ipAddress;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public RouteTable getRouteTable() {
		return routeTable;
	}

	public void setRouteTable(RouteTable routeTable) {
		this.routeTable = routeTable;
	}
	
	public HashMap<String, Integer> getNeighbors() {
		return neighbors;
	}

	public void setNeighbors(HashMap<String, Integer> neighbors) {
		this.neighbors = neighbors;
	}

	public UDPClient getClient() {
		return client;
	}

	public void setClient(UDPClient client) {
		this.client = client;
	}

	public UDPServer getServer() {
		return server;
	}

	public void setServer(UDPServer server) {
		this.server = server;
	}
	
	public boolean isOn() {
		return this.isOn;
	}
	
	public void setOn(boolean isOn) {
		this.isOn = isOn;
	}

	public String toString() {
		return this.id + " " + this.ipAddress.toString() + " " + Integer.toString(this.port) + "\n" + routeTable.toString();
	}
	
	public void printNeighbors() {
		Set keySet = neighbors.keySet();
		Iterator iterator = keySet.iterator();
		System.out.println("Vizinhos do roteador");
		while(iterator.hasNext()) {
			System.out.println(iterator.next().toString());
		}
	}

	public void setTable(RouteTable routerTable) {
		this.routeTable = routerTable;
		
	}

}
